"""一个按钮组件"""

import pygame
from .label import Label 
from game_utils import color_to_rgb

class Button(object):
    def __init__(self,screen,text,text_color:str="#000000",bg_color:str="#ffffff",width:int=95,height:int=35):
        self.text = text
        self.text_color = text_color
        self.bg_color = bg_color
        self.width,self.height =  width,height

        self.screen = screen
        self.screen_rect = screen.get_rect()

        self.label = Label(self.text,self.text_color,self.bg_color)

        self.rect = pygame.Rect(0,0,self.width,self.height)
        self.rect.center = self.screen_rect.center
    
    def draw_button(self):
        self.label.rect.center = self.rect.center #把文字绘制在按钮中间
        self.screen.fill(color_to_rgb(self.bg_color),self.rect) #在屏幕填充一个矩形
        #self.screen.blit(self.label.image,self.label.rect) #把文本绘制到屏幕
        self.label.draw(self.screen)
    def set_alpha(self,value):
        self.label.image.set_alpha(value)
        self.screen